// assert.h - define our own ASSERT macro because we want to throw an
// exception in case of fault instead of aborting.
#ifndef _lib_common_assert_h_
#define _lib_common_assert_h_

#include "Common/Assertion.h"

// Usage:
//	ASSERT(tokenize_one("1234").eq(Token(1234)));
#define ASSERT(x)				\
	do {						\
		if (!(x))				\
			throw Assertion(	\
				__FILE__,		\
				__LINE__,		\
				"ASSERT(" # x ## ") failed.");	\
	} while (false)

// Usage:
//	ASSERT_MSG(1 == 0, "One was not zero.");
//	ASSERT_MSG(strlen(msg) < 512, msg);
//  ASSERT_MSG(loop_idx > 0, to_cstr(loop_idx));

#define ASSERT_MSG(x, reason)	\
	do {						\
		if (!(x))				\
			throw Assertion(	\
				__FILE__,		\
				__LINE__,		\
				"ASSERT(" # x ## ") failed", \
				reason);	\
	} while (false)

#endif